package jly521.com

/**
  * Created by cuiyufei on 2018/2/13.
  */

import org.apache.spark.SparkContext
import org.apache.spark.SparkConf

object WordCountLocal {

  def main(args: Array[String]) {
//    val inputFile =  "/home/kkxmoye/Downloads/file/file1.txt"   //无效操作
//    val inputFile =  "E:\\BaiduNetdiskDownload\\1.txt"   //setMaster：local 模式下 可以本地固定地址为输入
    val inputFile =  "hdfs://localhost:9000/input/1.txt"   //本地Hadoop配置
    val conf = new SparkConf()
    conf.setAppName("WordCount").setMaster("local")
    val sc = new SparkContext(conf)
    val textFile = sc.textFile(inputFile)
    val wordCount = textFile.flatMap(line => line.split(" ")).map(word => (word, 1)).reduceByKey((a, b) => a + b)
    wordCount.foreach(println)
    wordCount.saveAsTextFile("hdfs://localhost:9000/output/1.txt")
  }
}
